<!DOCTYPE HTML>
<html>
<head>
    <title><%= __('views.myEquipment')%></title>
    <% include common/meta.ejs %>
    <% include common/public.ejs %>
    <link rel="stylesheet" href="/stylesheets/title.css">
    <style>
        .weui_media_desc label{
            font-weight: 400;
        }
    </style>
</head>

<body>

<div class="weui_search_bar" id="search_bar">
    <form class="weui_search_outer">
        <div class="weui_search_inner">
            <i class="weui_icon_search"></i>
            <input type="search" class="weui_search_input" id="search_input" placeholder="<%= __('views.search')%>" required/>
            <a href="javascript:" class="weui_icon_clear" id="search_clear"></a>
        </div>
        <label for="search_input" class="weui_search_text" id="search_text">
            <i class="weui_icon_search"></i>
            <span><%= __('views.search')%></span>
        </label>
    </form>
    <a href="javascript:" class="weui_search_cancel" id="search_cancel"><%= __('views.delete')%></a>
</div>

<div class="button_sp_area" style="margin: 0.25rem;">
    <a href="addEquip" class="weui_btn weui_btn_plain_default" style="font-size: 17px;line-height: 2;"><%= __('views.addEquipment')%></a>
</div>

<div class="weui_panel">
    <div class="weui_panel_bd dianzuk" id = 'list'>
    </div>
</div>
<input type="hidden" id="pageSize" value="10" />
<input type="hidden" id="pageNumber" value="0" />

<% include common/footer.ejs %>
<script>
    "use strict";
    $(function(){
        const customerId = '<%= userData.customerId %>';
        const accountType = '<%= userData.type %>';
        $('#search_input').focus(function(){
            $(this).closest('.weui_search_bar').addClass('weui_search_focusing');
        });
        $("#list").empty();
        $('#loadingDiv').html('<div class="infinite-preloader"></div>'+Dolphin.i18n.get("views.loading")+'...');
        $("#pageNumber").val("0");

        let data = {
            "_day":'1',
            "pageSize" : $("#pageSize").val(),
            "pageNumber" : "0"
        };
        if(accountType == 2){
            data.customerId = customerId;
        }else{
            data._areaId = customerId;
        }
        Dolphin.ajax({
            url: '/api/4e149d0fb488470fb3e493ade50564b6',
            type: Dolphin.requestMethod.POST,
            data: Dolphin.json2string({ "properties" : data }),
            onSuccess: function (reData) {
                $.each(reData.rows,function(i,n){
                    $('<div class="weui_media_box weui_media_text show_detail" >' +
                        '<h4 class="weui_media_title">'+n.code+'</h4>' +
                        '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.store")+'：</label>'+n.customerName+'</p>' +
                        '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.province")+'：</label>'+n.province+ ' <label>'+Dolphin.i18n.get("views.store")+'：</label>'+n.city+'</p>' +
                        '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.status")+
                        '：</label>'+n.statusName+'|<label>'+Dolphin.i18n.get("views.focusing")+
                        '：</label>'+(n.focus?Dolphin.i18n.get("views.looseFocus"):Dolphin.i18n.get("views.normal"))+
                        '|<label>'+Dolphin.i18n.get("views.powerVolumn")+'：</label>'+(n.voltage?n.voltage+'%' : '-')+'</p>' +
                        '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.recentOnlineTime")+'：</label>'+(n.lastReceiveTime ? Dolphin.longDate2string(n.lastReceiveTime,'yyyy-MM-dd hh:mm:ss'):'-')+'</p>' +
                        '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.totalIntradayEntry")+'：</label>'+
                        (n.properties.dxIn?n.properties.dxIn: '-')+ ' <label>'+Dolphin.i18n.get("views.toalIntradayExit")+'：</label>'+(n.properties.dxOut?n.properties.dxOut:'-')+'</p>' +
                        '</div>').click(function(){
                        location.href = 'addEquip?id='+n.id;
                    }).appendTo("#list");
                })
                $("#pageNumber").val(Number.parseInt($("#pageNumber").val())+1);
                $("#loadingDiv").empty();
            }
        });
        let loading = false;  //状态标记
        $(document.body).infinite().on("infinite", function() {
            if(loading) return;
            loading = true;
            setTimeout(function() {
                console.log($("#pageSize").val());
                console.log($("#pageNumber").val());
                let tempCondi = {
                    "customerId" : customerId,
                    "_day":'1',
                    "pageSize" : $("#pageSize").val(),
                    "pageNumber" : $("#pageNumber").val()
                }
                Dolphin.ajax({
                    url: '/api/4e149d0fb488470fb3e493ade50564b6',
                    type: Dolphin.requestMethod.POST,
                    data: Dolphin.json2string({ "properties" : tempCondi }),
                    onSuccess: function (reData) {
                        console.log(reData);
                        if( reData.rows == undefined || reData.rows.length == 0){
                            $(document.body).destroyInfinite();
                            $("#loadingDiv").empty();
                        }else{
                            $.each(reData.rows,function(i,n){
                                $('<div class="weui_media_box weui_media_text show_detail" >' +
                                    '<h4 class="weui_media_title">'+n.code+'</h4>' +
                                    '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.store")+':</label>'+n.customerName+'</p>' +
                                    '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.province")+':</label>'+n.province+ ' <label>'+Dolphin.i18n.get("views.city")+':</label>'+n.city+'</p>' +
                                    '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.status") +':</label>'+
                                    n.statusName+'|<label>'+Dolphin.i18n.get("views.focusing")+':</label>'+(n.focus?Dolphin.i18n.get("views.looseFocus"):Dolphin.i18n.get("views.normal"))+
                                    '|<label>'+Dolphin.i18n.get("views.powerVolumn")+':</label>'+(n.voltage?n.voltage+'%' : '-')+'</p>' +
                                    '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.recentOnlineTime")+':</label>'+(n.lastReceiveTime ? Dolphin.longDate2string(n.lastReceiveTime,'yyyy-MM-dd hh:mm:ss'):'-')+'</p>' +
                                    '<p class="weui_media_desc"><label>'+Dolphin.i18n.get("views.totalIntradayEntry")+':</label>'+(n.properties.dxIn?n.properties.dxIn: '-')+
                                    ' <label>'+Dolphin.i18n.get("views.toalIntradayExit")+':</label>'+(n.properties.dxOut?n.properties.dxOut:'-')+'</p>' +
                                    '</div>').click(function(){
                                    location.href = 'addEquip?id='+n.id;
                                }).appendTo("#list");
                            })
                            $("#pageNumber").val(Number.parseInt($("#pageNumber").val())+1);
                            loading = false;
                        }
                    }
                });
            }, 1500);   //模拟延迟
        });
        $("#search_input").blur(function(){
            let that = this;
            $(this).closest('.weui_search_bar').removeClass('weui_search_focusing');

            if($('#loadingDiv').html() == ''){
                $('#loadingDiv').html('<div class="infinite-preloader"></div>'+ Dolphin.i18n.get("views.loading")+'...')
            }
            let search = {
                "customerId" : customerId,
                "_day":'1'
            };
            $("#pageNumber").val("0");
            if($(that).val() == ''){
                search.pageSize = "10";
                search.pageNumber = "0";
            }else{
                search.code_like = $(that).val();     //<%= queryData.search %>
            }
            $("#list").empty();
            Dolphin.ajax({
                url: '/api/4e149d0fb488470fb3e493ade50564b6',
                type: Dolphin.requestMethod.POST,
                data: Dolphin.json2string({ "properties" : search }),
                onSuccess: function (reData) {
                    $.each(reData.rows,function(i,n){
                        $('<div class="weui_media_box weui_media_text show_detail" >' +
                            '<h4 class="weui_media_title">'+n.code+'</h4>' +
                            '<p class="weui_media_desc">'+ Dolphin.i18n.get("views.store")+':'+n.customerName+'</p>' +
                            '<p class="weui_media_desc">'+ Dolphin.i18n.get("views.province")+':'+n.province+Dolphin.i18n.get("views.city")+ ':'+n.city+'</p>' +
                            '<p class="weui_media_desc">'+Dolphin.i18n.get("views.status")
                            +':'+n.statusName+'|'+Dolphin.i18n.get("views.focusing")+':'+(n.focus?Dolphin.i18n.get("views.looseFocus"):Dolphin.i18n.get("views.normal"))
                            +'|'+Dolphin.i18n.get("views.powerVolumn")+':'+(n.voltage?n.voltage+'%' : '-')+'</p>' +
                            '<p class="weui_media_desc">'+Dolphin.i18n.get("views.recentOnlineTime")+':'+(n.lastReceiveTime ? Dolphin.longDate2string(n.lastReceiveTime,'yyyy-MM-dd hh:mm:ss'):'-')+'</p>' +
                            '<p class="weui_media_desc">'+Dolphin.i18n.get("views.totalIntradayEntry")+':'+(n.properties.dxIn?n.properties.dxIn: '-')+
                            Dolphin.i18n.get("views.toalIntradayExit")+':'+(n.properties.dxOut?n.properties.dxOut:'-')+'</p>' +
                            '</div>').click(function(){
                            location.href = 'addEquip?id='+n.id;
                        }).appendTo("#list");
                    });
                    if($(that).val() != ''){
                        $(document.body).destroyInfinite();
                        $("#loadingDiv").empty();
                    }else{
                        $(document.body).infinite();
                        $("#pageNumber").val(Number.parseInt($("#pageNumber").val())+1);
                    }
                }
            });
        });
    });

</script>
<div class="weui-infinite-scroll" id="loadingDiv">
</div>
</body>
</html>